package com.matchmealpha;

import java.util.ArrayList;

import android.app.ActivityGroup;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class TimelineGroup extends ActivityGroup {
	public static TimelineGroup timelineGroup;
	private ArrayList<View> timelineHistory;
	private String curruser;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		/*** Shared Pref ***/
		SharedPreferences settings = getSharedPreferences(
				"matchme_preferences", 0);
		curruser = settings.getString("username", "");
		
		this.timelineHistory = new ArrayList<View>();
		timelineGroup = this;
		Intent intent = new Intent(this, TimelineActivity.class)
		.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		intent.putExtra("curruser", curruser);
		intent.putExtra("back", false);
		intent.putExtra("relationship", false);
		intent.putExtra("callerID", MatchMeTabWidget.TIMELINE);
		View view = getLocalActivityManager().startActivity(
				"TimelineActivity",intent).getDecorView();
		replaceView(view);
	}

	public void replaceView(View v) {
		timelineHistory.add(v);
		setContentView(v);
	}

	public void back() {
		if (timelineHistory.size() > 0) {
			timelineHistory.remove(timelineHistory.size() - 1);
			setContentView(timelineHistory.get(timelineHistory.size() - 1));
		} else {
			finish();
		}
	}

	@Override
	public void onBackPressed() {
		TimelineGroup.timelineGroup.back();
		return;
	}

	public ArrayList<View> getHistory() {
		return timelineHistory;
	}
}
